package com.zhang.serviceverificationcode.controller;

import com.zhang.internalcommon.dto.ResponseResult;
import com.zhang.internalcommon.response.NumberCodeResponse;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class NumberCodeController {
	@GetMapping("/numberCode/{size}")
	public ResponseResult<NumberCodeResponse> numberCode(@PathVariable("size") int size) {
		double random = Math.random();
		int code = (int)((random * 9 + 1) * (Math.pow(10, size - 1)));
		NumberCodeResponse numberCodeResponse = new NumberCodeResponse();
		numberCodeResponse.setNumberCode(code);
		// JSONObject result = new JSONObject();
		// result.put("code", "1");
		// result.put("message", "success");
		// JSONObject data = new JSONObject();
		// data.put("numberCode", code);
		// result.put("data", data);
		return ResponseResult.success(numberCodeResponse);
	}

	// public static void main(String[] args) {
	// 	double random = Math.random();
	// 	// System.out.println(random);
	// 	double v = (int) ((random * 9 + 1) * (Math.pow(10, 5)));
	// 	System.out.println(v);
	// }
}
